<template>
	<view class="container padding-top">
		<view
			class="margin-left-sm margin-right-sm margin-bottom bg-white radius10 padding flex justify-center align-center flex-direction">
			<view class="text-15 text-333">
				账户余额（元）
			</view>
			<view class="text-bold text-221815 margin-top text-36">
				{{parseFloat(account.amount/ 100).toFixed(2)}}
			</view>
			<view class="flex justify-start align-center margin-top"
				@click="toPage('/filePage/pages/balance-details/balance-details')">
				<view class="text-999 text-df">
					查看明细
				</view>
				<view class="cuIcon-right">

				</view>
			</view>
			<view class="flex">

				<view @click="toPage('/filePage/pages/cash/cash')"
					class="bg-color text-15 text-white  round btn margin-top">
					充值
				</view>
				<view @click="toPage('/filePage/pages/reflect/reflect')"
					class="bg-color text-15 text-white  round btn margin-top">
					提现
				</view>
			</view>

		</view>
		<view class="margin-sm padding flex justify-between align-center bg-white radius5">
			<view class="flex justify-start align-center" style="width: 80%;">
				<view class="text-36 color" style="width: 40%;text-align: center;">
					{{ parseFloat(deposit.amount/ 100).toFixed(2)}}
				</view>
				<view class="margin-left">
					<view class="text-sm text-181818">
						我的押金（元）
					</view>
					<view class="flex justify-start align-center margin-top-xs"
						@click="toPage('/filePage/pages/deposit/deposit')">
						<view class="text-13 text-666">
							查看押金变动记录
						</view>
						<view class="cuIcon-right">

						</view>
					</view>
				</view>
			</view>
			<view class="color btn2 round"@click="submit">
				提现
			</view>

		</view>
		<view class="margin-sm padding flex justify-between align-center bg-white radius5">
			<view class="flex justify-start align-center" style="width: 80%;">
				<view class="text-36 color" style="width: 40%;text-align: center;">
					{{score.point}}
				</view>
				<view class="margin-left">
					<view class="text-sm text-181818">
						我的积分
					</view>
					<view class="flex justify-start align-center margin-top-xs"
						@click="toPage('/filePage/pages/score/score')">
						<view class="text-13 text-666">
							查看积分变动记录
						</view>
						<view class="cuIcon-right">

						</view>
					</view>
				</view>
			</view>
			<view class="color btn2 round" @click="toPage('/filePage/pages/points-mall/points-mall')">
				兑换
			</view>
		</view>
		<view class="margin-sm padding flex justify-between align-center bg-white radius5">
			<view class="flex justify-start align-center" style="width: 80%;">
				<view class="text-36 color" style="width: 40%;text-align: center;">
					{{credit.credit}}
				</view>
				<view class="margin-left">
					<view class="text-sm text-181818">
						我的信用分
					</view>
					<view class="flex justify-start align-center margin-top-xs"
						@click="toPage('/filePage/pages/credit/credit')">
						<view class="text-13 text-666">
							查看信用分变动记录
						</view>
						<view class="cuIcon-right">

						</view>
					</view>
				</view>
			</view>
			<view class="color btn2 round" @click="toPage('/filePage/pages/customer/customer')">
				客服
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: {},
				deposit: {},
				score: {},
				credit: {}
			};
		},
		onShow() {
			this.getAccount()
			this.getDeposit()
			this.getScore()
			this.getCredit()
		},
		
		methods: {
			toPage(url) {
				this.$util.openNewPage(url)
			},
			async getAccount() {
				const [err, rs] = await this.$get(this.$api.account, {
					userId: uni.getStorageSync('userId')
				})
				if (rs) {
					this.account = rs.data
				}
			},
			async getDeposit() {
				const [err, rs] = await this.$get(this.$api.deposit, {
					userId: uni.getStorageSync('userId')
				})
				if (rs) {
					this.deposit = rs.data
				}
			},
			async getScore() {
				const [err, rs] = await this.$get(this.$api.getUserPointByUserId, {
					userId: uni.getStorageSync('userId')
				})
				if (rs) {
					this.score = rs.data
				}
			},
			async getCredit() {
				const [err, rs] = await this.$get(this.$api.credit, {
					userId: uni.getStorageSync('userId')
				})
				if (rs) {
					this.credit = rs.data
				}
			},
			submit(){
				console.log(this.deposit.amount)
				if(this.deposit.amount==0){
					return this.$util.msg('保证金额为0,不允许提现')
				}
				console.log(this.deposit.amount)
				const that = this
				const data  = {payType:2,userId:uni.getStorageSync('userId'),type:2,amount:this.deposit.amount}
				uni.showModal({
			       content: '你确定提现吗',
				    success: function (res) {
				        if (res.confirm) {
				            console.log('用户点击确定');
							that.$jsonPost(that.$api.depoCreate,data).then(res=>{
								const  [err,rs]  = res
								if(rs){
									that.$util.msg(rs.message)
									that.getDeposit()
								}
							})
							
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			}
		}
	}
</script>

<style lang="scss">
	.btn {
		width: 150rpx;
		height: 60rpx;
		margin-right: 20rpx;
		text-align: center;
		line-height: 60rpx;
		margin-bottom: 30rpx;
	}

	.btn2 {
		padding: 14rpx 0;
		width: 20%;
		border: 1rpx solid;
		text-align: center;
	}

	.text-36 {
		font-size: 40rpx !important;
	}
</style>
